/**
 * 首页js封装
 * Copyright (c) 2022 fanwei
 */
$(function () {
    $('#fw-switch-btn').on('click', function () {
        if($('.page-wrapper').hasClass('slider-navigation-open')) {
            $('.slider-navigation').removeClass('slider-navigation-open');
            $('.page-wrapper').removeClass('slider-navigation-open');
            $('.index-wrapper').removeClass('slider-navigation-open');
            $('.fw-switch > div').removeClass('slider-navigation-open');
        }else {
            $('.page-wrapper').addClass('slider-navigation-open');
            $('.index-wrapper').addClass('slider-navigation-open');
            $('.fw-switch > div').addClass('slider-navigation-open');
            $('.slider-navigation').addClass('slider-navigation-open');
        }
    });

    // 系统时钟
    var clock = new Clock();
    clock.display(document.getElementById("clock"));

    // 操作栏-展开/折叠
    $('#fw-foldbar-outdent').on('click', function () {
        operOutdent();
    });
    $('#fw-foldbar-indent').on('click', function () {
        operIndent();
    });

    // 展开操作栏
    setTimeout(function () {
        operOutdent();
    }, 500);

    $(".fw-modal-actions-menus").on('click', 'li a', function (event) {
        event.stopPropagation();
        var menuId = $(this).data("menuid");
        var menuIcon = $(this).data("menuicon");
        var menuTarget = $(this).data("menutarget");
        if (menuTarget == "menuBlank") {
            var dataUrl = $(this).attr('href');
            window.open(dataUrl);
            return false;
        }
        $("#fw-switch-btn span").removeClass().addClass(menuIcon);
        $(".fw-menu-add a").data("id", menuId);
        $(".fw-menu-add a").data("icon", menuIcon);
        /*if (menuIcon === "am-icon-database") {
            $(".fw-menu-add a").removeClass().addClass("am-icon-search-plus");
        } else {
            $(".fw-menu-add a").removeClass().addClass("am-icon-plus");
        }*/
        $("#fw-offcanvas-switch-sys").modal('close');
        loadSysMenus(menuId, null);
    });

    $("#fw-menu-do").on('click', 'a', function (event) {
        event.stopPropagation();
        var menuId = $(this).data("menuid");
        var menuTarget = $(this).data("menutarget");
        if (menuTarget == "menuBlank") {
            var dataUrl = $(this).attr('href');
            window.open(dataUrl);
            return false;
        }
        if(menuTarget == 'menuCustom-DbConnect') {
            $(".fw-search .am-input-group").css('width', 'auto');
            $(".fw-search .am-input-group .am-input-group-btn").removeClass('am-hide');
        }else {
            $(".fw-search .am-input-group .am-input-group-btn").addClass('am-hide');
            $(".fw-search .am-input-group").css('width', '100%');
        }
        $("#fw-menu-do a").removeClass("fw-active");
        $(this).addClass("fw-active");
        $("#fw-item-accordion .fw-oper-message-list").removeClass("am-in");
        $("#fw-item-accordion #do-item-menu-" + menuId).addClass("am-in");
    });


    $("#fw-item-accordion").on('click', '.cmenu', function (event) {
        event.stopPropagation();

        var menuId = $(this).data("menuid");
        var menuName = $(this).data("menuname");
        var menuIcon = $(this).data("menuicon");
        var menuUrl = $(this).data("menuurl");
        var menuTarget = $(this).data("menutarget");
        if (menuTarget == "menuBlank") {
            var dataUrl = $(this).attr('href');
            window.open(dataUrl);
            return false;
        }

        $(".cmenu").removeClass("fw-active");
        $(this).addClass("fw-active");

        // 新建标签页
        add_menu_tab(menuId, menuName, menuIcon, menuUrl);
    });
    $("#fw-item-accordion").on('click', '.cmenu .cmenu-blank-open', function (event) {
        event.stopPropagation();

        var menuUrl = $(this).closest("#fw-item-accordion .cmenu").data("menuurl");
        window.open(menuUrl);

        return false;
    });

    // 数据库连接操作
    $("#fw-item-accordion").on('click', '.connect', function (event) {
        var $connect_e = $(this);
        var connect_id = $(this).data("connect_id");
        var connect_name = $(this).data("connect_name");
        var connect_group = $(this).data("connect_group");
        var _connect_database = $("#database-" + connect_id);
        var _connect_status_tag = $("#connect-status-tag-" + connect_id);
        var _database_item = $("#database-" + connect_id + " .database-item");
        var _database_btn_group = $("#database-" + connect_id + " .database-item-opers");

        if (_connect_database.is(":visible") && $(this).hasClass("fw-active")) {
            $(this).removeClass("fw-active");
            _connect_database.hide();
            _database_item.removeClass("database-item-active");
            _database_btn_group.addClass("am-hide");
            _connect_status_tag.removeClass("fw-active");
            _connect_status_tag.text("[未连接]");
            return;
        }/*else {
            $(".connect").removeClass("fw-active");
            $(".connect .database-list").hide();
            $(".connect .database-list .database-item").removeClass("database-item-active");
            $(".connect .database-list .database-item .database-item-opers").addClass("am-hide");
            $(".connect .connect-status-tag").removeClass("fw-active");
            $(".connect .connect-status-tag").text("[未连接]");
        }*/
        $(this).addClass("fw-active");

        $.ajax({
            type: "get",
            async: true,
            url: ctx + "osfw/dbadminer/database/list/" + connect_id,
            success: function (res) {
                _connect_database.html("");
                _connect_database.hide();
                if (res.code == web_status.SUCCESS) {
                    _connect_database.show();
                    _connect_status_tag.addClass("fw-active");
                    _connect_status_tag.text("[已连接]");
                    $.each(res.data, function (i, database_name) {
                        var database_item =
                            `<div class="database-item database-item-group-` + connect_group + `" data-connect_id="` + connect_id + `" data-connect_name="` + connect_name + `" data-connect_group="` + connect_group + `" data-database_name="` + database_name + `">
                                    <div class="database-item-header">
                                        <a class="am-text-truncate am-icon-database am-icon-fw show-database" title=" ` + database_name + ` "> ` + database_name + `</a>
                                        <a class="am-icon-search-plus am-icon-fw new-sqlexcute" title=" 新建SQL查询 "></a>
                                    </div>
                                    <div class="database-item-opers am-hide">
                                        <div>
                                            <a class="am-btn am-btn-xs am-icon-table am-icon-fw database-table"> 表</a>
                                            <a class="am-btn am-btn-xs am-icon-list-alt am-icon-fw database-view"> 视图</a>
                                            <a class="am-btn am-btn-xs am-icon-facebook am-icon-fw database-func"> 函数</a>
                                        </div>
                                        <div>
                                            <a class="am-btn am-btn-xs am-icon-sort-alpha-asc am-icon-fw database-index"> 索引</a>
                                            <a class="am-btn am-btn-xs am-icon-sort-numeric-asc am-icon-fw database-sequence"> 序列</a>
                                            <a class="am-btn am-btn-xs am-icon-cubes am-icon-fw database-type"> 类型</a>
                                        </div>
                                    </div>
                                </div>`;
                        _connect_database.append(database_item);
                    });
                } else {
                    _connect_database.hide();
                    _connect_status_tag.removeClass("fw-active");
                    _connect_status_tag.text("[未连接]");
                }
            },
            error: function (xhr, status, error) {
                var errorMessage = "请求失败，请稍后再试。";
                if (xhr.status === 0) {
                    errorMessage = "网络连接失败，请检查网络设置。";
                } else if (xhr.status === 404) {
                    errorMessage = "请求的资源不存在。";
                } else if (xhr.status === 500) {
                    var responseText = JSON.parse(xhr.responseText);
                    errorMessage = responseText.msg;
                } else if (error === "timeout") {
                    errorMessage = "请求超时，请稍后再试。";
                }
                $connect_e.removeClass("fw-active");
                // 显示错误提示给用户
                log.error(errorMessage);
            }
        });
    });
    $("#fw-item-accordion").on('click', '.connect .database-list', function (event) {
        event.stopPropagation();
        $(".connect").removeClass("fw-active");
        $(this).parents(".connect").addClass("fw-active");
    });
    $("#fw-item-accordion").on('click', '.connect .show-database', function (event) {
        event.stopPropagation();
        $(".connect").removeClass("fw-active");
        $(this).parents(".connect").addClass("fw-active");

        $(this).parents(".connect").find(".database-item-opers").addClass("am-hide");
        var _btn_group = $(this).parent().next(".database-item-opers");
        if (!$(this).parents(".database-item").hasClass("database-item-active")) {
            $(this).parents(".connect").find(".database-item").removeClass("database-item-active");
            $(this).parents(".database-item").addClass("database-item-active");
            _btn_group.removeClass("am-hide");
        } else {
            $(this).parents(".connect").find(".database-item").removeClass("database-item-active");
            _btn_group.addClass("am-hide");
        }
    });
    $("#fw-item-accordion").on('click', '.connect .new-sqlexcute', function (event) {
        event.stopPropagation();
        $(".connect").removeClass("fw-active");
        $(this).parents(".connect").addClass("fw-active");
        // 新建查询
        add_connect_tab($(this).parents(".database-item").data("connect_id"), $(this).parents(".database-item").data("connect_name"), $(this).parents(".database-item").data("connect_group"), $(this).parents(".database-item").data("database_name"));
    });
    $("#fw-item-accordion").on('click', '.connect .database-table', function (event) {
        event.stopPropagation();
        $(".connect").removeClass("fw-active");
        $(this).parents(".connect").addClass("fw-active");
        // 查看表
        $("#fw-header-logo-title").text("表");
        $('.moxia_iframe').addClass("am-hide");
        var target = $('.moxia_iframe[data-id="0"]');
        target.removeClass("am-hide");

        var _database = $(this).parents(".database-item")[0];
        var url = ctx + "osfw/dbadminer/database/table/" + $(_database).data("connect_id") + "/" + $(_database).data("connect_name") + "/" + $(_database).data("database_name");
        target.attr('src', url).ready();
    });
    $("#fw-item-accordion").on('click', '.connect .database-view', function (event) {
        event.stopPropagation();
        $(".connect").removeClass("fw-active");
        $(this).parents(".connect").addClass("fw-active");
        // 查看视图
        $("#fw-header-logo-title").text("视图");
        $('.moxia_iframe').addClass("am-hide");
        var target = $('.moxia_iframe[data-id="0"]');
        target.removeClass("am-hide");
        var _database = $(this).parents(".database-item")[0];
        var url = ctx + "osfw/dbadminer/database/view/" + $(_database).data("connect_id") + "/" + $(_database).data("connect_name") + "/" + $(_database).data("database_name");
        target.attr('src', url).ready();
    });
    $("#fw-item-accordion").on('click', '.connect .database-func', function (event) {
        event.stopPropagation();
        $(".connect").removeClass("fw-active");
        $(this).parents(".connect").addClass("fw-active");
        // 查看函数
        $("#fw-header-logo-title").text("函数");
        $('.moxia_iframe').addClass("am-hide");
        var target = $('.moxia_iframe[data-id="0"]');
        target.removeClass("am-hide");
        var _database = $(this).parents(".database-item")[0];
        var url = ctx + "osfw/dbadminer/database/func/" + $(_database).data("connect_id") + "/" + $(_database).data("connect_name") + "/" + $(_database).data("database_name");
        target.attr('src', url).ready();
    });
    $("#fw-item-accordion").on('click', '.connect .database-index', function (event) {
        event.stopPropagation();
        $(".connect").removeClass("fw-active");
        $(this).parents(".connect").addClass("fw-active");
        // 查看索引
        $("#fw-header-logo-title").text("索引");
        $('.moxia_iframe').addClass("am-hide");
        var target = $('.moxia_iframe[data-id="0"]');
        target.removeClass("am-hide");
        var _database = $(this).parents(".database-item")[0];
        var url = ctx + "osfw/dbadminer/database/index/" + $(_database).data("connect_id") + "/" + $(_database).data("connect_name") + "/" + $(_database).data("database_name");
        target.attr('src', url).ready();
    });
    $("#fw-item-accordion").on('click', '.connect .database-type', function (event) {
        event.stopPropagation();
        $(".connect").removeClass("fw-active");
        $(this).parents(".connect").addClass("fw-active");
        // 查看类型
        $("#fw-header-logo-title").text("类型");
        $('.moxia_iframe').addClass("am-hide");
        var target = $('.moxia_iframe[data-id="0"]');
        target.removeClass("am-hide");
        var _database = $(this).parents(".database-item")[0];
        var url = ctx + "osfw/dbadminer/database/type/" + $(_database).data("connect_id") + "/" + $(_database).data("connect_name") + "/" + $(_database).data("database_name");
        target.attr('src', url).ready();
    });
    $("#fw-item-accordion").on('click', '.connect .database-sequence', function (event) {
        event.stopPropagation();
        $(".connect").removeClass("fw-active");
        $(this).parents(".connect").addClass("fw-active");
        // 查看序列
        $("#fw-header-logo-title").text("序列");
        $('.moxia_iframe').addClass("am-hide");
        var target = $('.moxia_iframe[data-id="0"]');
        target.removeClass("am-hide");
        var _database = $(this).parents(".database-item")[0];
        var url = ctx + "osfw/dbadminer/database/sequence/" + $(_database).data("connect_id") + "/" + $(_database).data("connect_name") + "/" + $(_database).data("database_name");
        target.attr('src', url).ready();
    });

});


function loadSysMenus(parentId, menuName) {
    $.ajax({
        type: "post",
        async: false,
        url: ctx + "osfw/system/manage/menu/selectMenusByUser",
        data: {
            "parentId": parentId,
            "menuName": menuName
        },
        success: function (res) {
            if (res.code == web_status.SUCCESS && res.data != null) {
                var menus = res.data;
                if (parentId == 0) {
                    initSysMenus(menus);
                } else {
                    initFunMenus(menus);
                }
            }
        },
        error: function (xhr, status, error) {
            var errorMessage = "请求失败，请稍后再试。";
            if (xhr.status === 0) {
                errorMessage = "网络连接失败，请检查网络设置。";
            } else if (xhr.status === 404) {
                errorMessage = "请求的资源不存在。";
            } else if (xhr.status === 500) {
                // var responseText = JSON.parse(xhr.responseText);
                errorMessage = "服务器异常，请联系技术人员。";
            } else if (error === "timeout") {
                errorMessage = "请求超时，请稍后再试。";
            }
            // 显示错误提示给用户
            console.error(errorMessage);
        }
    });
}

// 初始化系统菜单
function initSysMenus(menus) {
    $(".inner-wrapper .slide:not(.first)").remove();
    $(".slider-pager").remove();
    var defaultMenuSetup = false;
    for (var i = 0; i < menus.length; i++) {
        var sys_menu_slide, sys_menu_item, sys_menu_href, sys_menu_default, sys_background_image;
        var menu = menus[i];
        if (menu.url != '#') {
            if ($.common.isNotEmpty(menu.url) && menu.url.indexOf("http://") != -1) {
                sys_menu_href = menu.url;
            } else {
                sys_menu_href = ctx + menu.url;
            }
        } else {
            sys_menu_href = 'javascript: void(0)';
        }
        if(!defaultMenuSetup && menu.target != 'menuBlank') {
            sys_menu_default = 'defaultMenu';
            defaultMenuSetup = true;
        }else {
            sys_menu_default = '';
        }
        if($.common.isNotEmpty(menu.background)) {
            if(menu.background.indexOf("#") != -1 || menu.background.indexOf("http") != -1 || menu.background.indexOf("/osfw/") != -1) {
                sys_background_image = menu.background;
            }else {
                sys_background_image = "data:image/png;base64," + menu.background;
            }
        }else {
            sys_background_image = ctx + "osfw/framework/index/assets/img/bg-"+i+".jpg";
        }
        sys_menu_slide = '<div class="slide hide-description ' + sys_menu_default + '" id="' + menu.menuId + '" data-menutarget="' + menu.target + '" data-menuurl="' + sys_menu_href + '" data-menuicon="' + menu.icon + '">'+
            '   <div class="description">' +
            '       <h2 class="animate">' + menu.menuName + '</h2>' +
            '   </div>' +
            '   <div class="image" data-background="' +sys_background_image + '"></div>' +
            '</div>';
        $(".inner-wrapper").append(sys_menu_slide);
        if(sys_background_image.indexOf("#") != -1) {
            sys_menu_item =
                '<div class="item">' +
                '   <a href="#' + menu.menuId + '">' + menu.menuName +
                '       <span style="background-color: ' + sys_background_image + '"></span>' +
                '   </a>' +
                '</div>';
        }else {
            sys_menu_item =
                '<div class="item">' +
                '   <a href="#' + menu.menuId + '">' + menu.menuName +
                '       <span style="background-image: url(' + sys_background_image + ')"></span>' +
                '   </a>' +
                '</div>';
        }
        $(".slider-pager").append(sys_menu_item);
    }
}

// 初始化菜单
function initFunMenus(menus) {
    $("#fw-menu-do a").remove();// 初始化左侧栏菜单
    $("#fw-item-accordion div").remove();// 初始化操作栏菜单
    for (var i = 0; i < menus.length; i++) {
        var menu = menus[i];

        // 初始化左侧栏菜单
        var fw_active = (i == 0 ? 'fw-active' : '');
        if (menu.url != '#') {
            if ($.common.isNotEmpty(menu.url) && menu.url.indexOf("http://") != -1) {
                var a = `<a data-menuid="` + menu.menuId + `" data-menutarget="` + menu.target + `" href="` + menu.url + `" class="am-icon-btn am-icon-fw ` + fw_active + `" title=" ` + menu.remark + `"><i class="` + menu.icon + `"></i><span>` + menu.menuName + `</span></a>`;
                $("#fw-menu-do").append(a);
            } else {
                var a = `<a data-menuid="` + menu.menuId + `" data-menutarget="` + menu.target + `" href="` + ctx + menu.url + `" class="am-icon-btn am-icon-fw ` + fw_active + `" title=" ` + menu.remark + `"><i class="` + menu.icon + `"></i><span>` + menu.menuName + `</span></a>`;
                $("#fw-menu-do").append(a);
            }
        } else {
            var a = `<a data-menuid="` + menu.menuId + `" data-menutarget="` + menu.target + `" href="javascript: void(0);" class="am-icon-btn am-icon-fw ` + fw_active + `" title=" ` + menu.remark + `"><i class="` + menu.icon + `"></i><span>` + menu.menuName + `</span></a>`;
            $("#fw-menu-do").append(a);
        }

        // 初始化操作栏菜单
        if (menu.target.indexOf('menuCustom') != -1) {
            var functionName = menu.target.replace('menuCustom-', '');
            var $function = window['init' + functionName + 'Menus'];
            //判断函数是否存在
            if ($function && typeof $function === 'function') {
                if(fw_active == 'fw-active' && functionName == 'DbConnect'){
                    $(".fw-search .am-input-group").css('width', 'auto');
                    $(".fw-search .am-input-group .am-input-group-btn").removeClass('am-hide');
                }
                // 执行函数
                $function(menu);
            }
        } else {
            if(fw_active == 'fw-active'){
                $(".fw-search .am-input-group .am-input-group-btn").addClass('am-hide');
                $(".fw-search .am-input-group").css('width', '100%');
            }
            initFunChildMenus(i, menu);
        }
    }
}

function initFunChildMenus(i, menu) {
    var do_item_menu_id = "do-item-menu-" + menu.menuId;
    $("#fw-item-accordion").append(`<div id="` + do_item_menu_id + `" class="fw-oper-message-list am-panel-collapse am-collapse ` + (i == 0 ? 'am-in' : '') + `"></div>`);
    for (var j = 0; j < menu.children.length; j++) {
        var cmenu = menu.children[j];
        if ($.isEmptyObject(cmenu.children)) {
            var cmenuE =
                `<div id="menu-` + cmenu.menuId + `" class="fw-list-item cmenu" data-menuid="` + cmenu.menuId + `" data-menuname="` + cmenu.menuName + `" data-menutarget="` + cmenu.target + `" data-menuicon="` + cmenu.icon + `" data-menuurl="` + ($.common.isNotEmpty(cmenu.url) && cmenu.url.indexOf("http://") != -1 ? cmenu.url : ctx + cmenu.url) + `">
                    <div class="fw-list-item-info">
                        <div class="fw-list-item-info-logo">
                            <span class="` + cmenu.icon + ` am-icon-fw"></span>
                        </div>
                        <div class="fw-list-item-info-name">
                            <div class="show-name">` + cmenu.menuName + `</div>
                        </div>
                        <div class="fw-list-item-info-status">
                            <span class="cmenu-remark am-ellipsis" title="` + cmenu.remark + `">` + ($.common.isEmpty(cmenu.remark) ? "..." : cmenu.remark) + `</span>
                            <span style="display: inline-block;">]</span>
                            <span class="cmenu-blank-open" title="新窗口打开"><i class="am-icon-external-link"></i></span>
                        </div>
                    </div>
                </div>`;
            $("#" + do_item_menu_id).append(cmenuE);
        } else {
            console.error("仅支持三级菜单");
        }
    }
}

function initDbConnectMenus(menu) {
    var do_item_menu_id = "do-item-menu-" + menu.menuId;
    $("#fw-item-accordion").append(`<div id="` + do_item_menu_id + `" class="fw-oper-message-list am-panel-collapse am-collapse am-in"></div>`);
    $.ajax({
        type: "get",
        async: false,
        url: ctx + "osfw/dbadminer/connect/list",
        /*data: {
            "parentId": parentId,
            "menuName": menuName
        },*/
        success: function (res) {
            if (res.code == web_status.SUCCESS && res.data != null) {
                var connects = res.data;
                for (var j = 0; j < connects.length; j++) {
                    var connect = connects[j];
                    var connectE =
                        `<div id="connect-` + connect.id + `" class="fw-list-item connect" data-connect_id="` + connect.id + `" data-connect_name="` + connect.name + `" data-connect_group="` + connect.groupFlag + `">
                            <div class="fw-list-item-info">
                                <div class="fw-list-item-info-logo">
                                    <span class="icon-` + connect.type + `"></span>
                                </div>
                                <div class="fw-list-item-info-name">
                                    <div class="show-name">` + connect.name + `</div>
                                </div>
                                <div class="fw-list-item-info-status">
                                    <span class="connect-group am-ellipsis connect-group-` + connect.groupFlag + `">` + connect.groupName + `</span>
                                     <span class="connect-group-` + connect.groupFlag + `" style="display: inline-block;">]</span>
                                    <span id="connect-status-tag-` + connect.id + `" class="connect-status-tag">[未连接]</span>
                                </div>
                            </div>
                            <div id="database-` + connect.id + `" class="database-list"></div>
                        </div>`;
                    $("#" + do_item_menu_id).append(connectE);
                }
            }
        },
        error: function (xhr, status, error) {
            var errorMessage = "请求失败，请稍后再试。";
            if (xhr.status === 0) {
                errorMessage = "网络连接失败，请检查网络设置。";
            } else if (xhr.status === 404) {
                errorMessage = "请求的资源不存在。";
            } else if (xhr.status === 500) {
                // var responseText = JSON.parse(xhr.responseText);
                errorMessage = "服务器异常，请联系技术人员。";
            } else if (error === "timeout") {
                errorMessage = "请求超时，请稍后再试。";
            }
            // 显示错误提示给用户
            console.error(errorMessage);
        }
    });
}

// 系统时钟
function Clock() {
    var date = new Date();
    this.year = date.getFullYear();
    this.month = date.getMonth() + 1;
    this.date = date.getDate();
    this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()];
    this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    this.toString = function () {
        return this.year + "年" + this.month + "月" + this.date + "日 " + this.hour + ":" + this.minute + ":" + this.second + " " + this.day;
    };
    this.toSimpleDate = function () {
        return this.hour + ":" + this.minute + ":" + this.second;
    };
    this.toDetailDate = function () {
        return this.year + "-" + this.month + "-" + this.date + " " + this.hour + ":" + this.minute + ":" + this.second;
    };
    this.display = function (ele) {
        var clock = new Clock();
        ele.innerHTML = clock.toString();
        window.setTimeout(function () {
            clock.display(ele);
        }, 1000);
    };
}


// 操作栏-展开/折叠
function operOutdent() {
    $(".fw-oper").removeClass("fw-oper-indent5s");
    $(".fw-oper").addClass("fw-oper-outdent5s");
    $(".fw-container").removeClass("fw-container-extension5s");
    $(".fw-container").addClass("fw-container-shrink5s");
    setTimeout(function () {
        $(".fw-oper > div").removeClass("am-hide");
        $("#fw-foldbar-outdent").addClass("am-hide");
        $('#fw-foldbar-indent').removeClass("am-hide");
    }, 500);
}

function operIndent() {
    $(".fw-oper > div").addClass("am-hide");
    $(".fw-oper").removeClass("fw-oper-outdent5s");
    $(".fw-oper").addClass("fw-oper-indent5s");
    $(".fw-container").removeClass("fw-container-shrink5s");
    $(".fw-container").addClass("fw-container-extension5s");
    setTimeout(function () {
        $("#fw-foldbar-indent").addClass("am-hide");
        $('#fw-foldbar-outdent').removeClass("am-hide");
    }, 500);
}


// 菜单/连接搜索
function searchMenu(obj) {
    var searchVal = $.trim($(obj).val());
    var menuid = $("#fw-menu-do a.fw-active").data("menuid");
    if($.common.isNotEmpty(searchVal)){
        var search = eval("/^.*?"+searchVal+".*?$/");    //拼接正则字符串，由eval()函数转为正则表达式
        var menutarget = $("#fw-menu-do a.fw-active").data("menutarget");
        if(menutarget == 'menuCustom-DbConnect') { //数据库连接筛选
            ''
            $.each($('#do-item-menu-'+menuid+' .fw-list-item'), function (index, item) {
                if(search.test($(item).data('connect_name'))) {
                    $(item).removeClass('am-hide');
                }else{
                    var testCount = $(item).find('.database-list .database-item').filter(function (index, item2) {
                        if(search.test($(item2).data('database_name'))) {
                            return true;
                        }
                        return false;
                    }).length;
                    if(testCount > 0) {
                        $(item).removeClass('am-hide');
                    }else {
                        $(item).addClass('am-hide');
                    }
                }
            });
        }else { //菜单筛选
            $.each($('#do-item-menu-'+menuid+' .fw-list-item'), function (index, item) {
                if(search.test($(item).data('menuname'))) {
                    $(item).removeClass('am-hide');
                }else{
                    $(item).addClass('am-hide');
                }
            });
        }
    }else {
        $('#do-item-menu-'+menuid+' .fw-list-item').removeClass("am-hide");
    }
    return false;
}


//  新建连接
function addConnect() {
    jianshezhong();
}


// 退出系统
function logout() {
    $.modal.confirm("确定要退出系统吗？", function () {
        storage.remove("api-key");
        storage.remove("api-token");
        location.href = ctx + 'osfw/logout';
    });
}
